// BusAp_BPA.cpp: implementation of the CBusAp_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Dat/BusAp_BPA.h"
//#include "Node_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBusAp_BPA::CBusAp_BPA()
{
	m_chType = '+';
	m_chSubType = 'A';
	m_chChangeCode = ' ';
    m_dPload = 0;
    m_dQload = 0;
    memset(m_strCardType,' ',2);
    m_strCardType[2] = '\0';
    m_dBshunt = 0;
    m_dGshunt = 0;
}

CBusAp_BPA::~CBusAp_BPA()
{

}

bool CBusAp_BPA::UpdateEx(char *buffer)
{
	bool bResult = CNode_BPA::UpdateEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CBus_BPA: UpdateEx): impossible!\n");
		return false;
	}
	strcpy(&buffer[18],m_strCardType);	
	DoubleToStr(m_dPload,&buffer[20],5);
	DoubleToStr(m_dQload,&buffer[25],5);
	DoubleToStr(m_dGshunt,&buffer[30],4);
	DoubleToStr(m_dBshunt,&buffer[34],4);
	
	return true;
}

bool CBusAp_BPA::FillEx(char *buffer)
{
	int i;
	//printf("CBusAp_BPA::FillEx\n");

	bool bResult = CNode_BPA::FillEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CBus_BPA: FillEx): no basic information!\n");
		return false;
	}

	for(i=0;i<2;i++)
	{
		if(!buffer[18+i])
			break;
		else
			m_strCardType[i] = buffer[18+i];
	}
	m_strCardType[2] = '\0';
	if(i!=2)
		return true;

	m_dPload = StrToDouble(&buffer[20],5);
	if(EndOfSec(&buffer[20],5))
		return true;

	m_dQload = StrToDouble(&buffer[25],5);
	if(EndOfSec(&buffer[25],5))
		return true;
	/*printf(m_strName);
	printf("\n");
	printf("%f %f %f ",m_dKV,m_dPload,m_dQload);*/
	m_dGshunt = StrToDouble(&buffer[30],4);
	if(EndOfSec(&buffer[30],4))
		return true;
	
	m_dBshunt = StrToDouble(&buffer[34],4);
	if(EndOfSec(&buffer[34],4))
		return true;

	
	return true;
}



CBusAp_BPA::CBusAp_BPA(CBusAp_BPA &busapBPA):CNode_BPA(busapBPA)
{
    m_dBshunt = busapBPA.m_dBshunt;
	m_dGshunt = busapBPA.m_dGshunt;
    strcpy(m_strCardType,busapBPA.m_strCardType);
	strcpy(m_strName,busapBPA.m_strName);
	m_dPload = busapBPA.m_dPload;
	m_dQload = busapBPA.m_dQload;
}

